package edu.hawaii.halealohacli.command;

import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import org.junit.Test;
import static org.junit.Assert.assertTrue;

/**
 * Tests for the SourceData.
 * 
 * @author Jordan Do
 */
public class TestSourceData {
  /**
   * Tests to sort using different comparators. Sorts each list and checks to make sure they order
   * by value and then name
   */
  // create list to hold dummy sourceData files
  List<SourceData> test = new ArrayList<SourceData>();
  // create dummy sourceData files
  SourceData a = new SourceData("a");
  SourceData b = new SourceData("b");
  SourceData c = new SourceData("c");

  /**
   * Constructor to hold a sample list.
   */
  public TestSourceData() {
    test.add(a);
    test.add(b);
    test.add(c);
  }

  /**
   * Test for carbonEmitted.
   */
  @Test
  public void testCarbonEmitted() {
    c.setCarbonEmitted(1);
    a.setCarbonEmitted(2);
    b.setCarbonEmitted(2);
    Collections.sort(test, SourceData.sortCarbonEmitted);
    assertTrue("first is c", test.get(0).getName().equals("c"));
    assertTrue("second is a", test.get(1).getName().equals("a"));
    assertTrue("third is b", test.get(2).getName().equals("b"));
  }

  /**
   * Test for energyConsumed.
   */
  @Test
  public void testEnergyConsumed() {
    c.setEnergyConsumed(2);
    a.setEnergyConsumed(3);
    b.setEnergyConsumed(2);
    Collections.sort(test, SourceData.sortEnergyConsumed);
    assertTrue("first is b", test.get(0).getName().equals("b"));
    assertTrue("second is c", test.get(1).getName().equals("c"));
    assertTrue("third is a", test.get(2).getName().equals("a"));
  }

  /**
   * Test for energyGenerated.
   */
  @Test
  public void testEnergyGenerated() {
    c.setEnergyGenerated(1);
    a.setEnergyGenerated(2);
    b.setEnergyGenerated(2);
    Collections.sort(test, SourceData.sortEnergyGenerated);
    assertTrue("first is c", test.get(0).getName().equals("c"));
    assertTrue("second is a", test.get(1).getName().equals("a"));
    assertTrue("third is b", test.get(2).getName().equals("b"));
  }

  /**
   * Test for powerConsumed.
   */
  @Test
  public void testPowerConsumed() {
    c.setPowerConsumed(2);
    a.setPowerConsumed(3);
    b.setPowerConsumed(2);
    Collections.sort(test, SourceData.sortPowerConsumed);
    assertTrue("first is b", test.get(0).getName().equals("b"));
    assertTrue("second is c", test.get(1).getName().equals("c"));
    assertTrue("third is a", test.get(2).getName().equals("a"));
  }

  /**
   * Test for powerGenerated.
   */
  @Test
  public void testPowerGenerated() {
    c.setPowerGenerated(2);
    a.setPowerGenerated(3);
    b.setPowerGenerated(2);
    Collections.sort(test, SourceData.sortPowerGenerated);
    assertTrue("first is b", test.get(0).getName().equals("b"));
    assertTrue("second is c", test.get(1).getName().equals("c"));
    assertTrue("third is a", test.get(2).getName().equals("a"));
  }

  /**
   * Test for Name.
   */
  @Test
  public void testName() {
    Collections.sort(test, SourceData.sortName);
    assertTrue("first is a", test.get(0).getName().equals("a"));
    assertTrue("second is b", test.get(1).getName().equals("b"));
    assertTrue("third is c", test.get(2).getName().equals("c"));
  }
  
  /**
   * Test for Time.
   */
  @Test  public void testTime() {
    a.setTime("2015-11-15");
    b.setTime("2016-11-15");
    c.setTime("2017-10-15");
    Collections.sort(test, SourceData.sortTime);
    assertTrue("first is a", test.get(0).getName().equals("a"));
    assertTrue("second is b", test.get(1).getName().equals("b"));
    assertTrue("third is c", test.get(2).getName().equals("c"));
  }
}
